package com.chat.login.controller;


import com.chat.common.vo.R;
import com.chat.login.domain.dto.LoginUserDTO;
import com.chat.login.domain.dto.RegisterUserDTO;
import com.chat.login.domain.vo.LoginUserVO;
import com.chat.login.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 登陆注册
 * @author weikjie
 * @since 2024-03-08
 */
@RestController
@Validated
@RequestMapping("/auth/user")
public class LoginController {
    @Autowired
    IUserService userService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public R<LoginUserVO> login(@Validated @RequestBody LoginUserDTO loginUserDTO){
        return userService.login(loginUserDTO);
    }

    /**
     * 用户注册
     */
    @PostMapping("/register")
    public R<String> register(@Validated @RequestBody RegisterUserDTO registerUserDTO){
        return userService.register(registerUserDTO);
    }

    /**
     * 激活账号
     * @param account
     * @return
     */
    @GetMapping("/validate_account")
    public R validateAccount(@RequestParam("account") String account){
        return userService.validateAccount(account);
    }


    /**
     * 退出登录
     * @param token
     * @return
     */
    @GetMapping("/loginOff")
    public R loginOff(@RequestHeader("token") String token){
        return userService.loginOff(token);
    }
}
